//trapbox.txt - A trapped box.
//Cell 0 - Difficulty of trap.
//Cell 1 - The effect created.
//Cell 2,3 - The sdf which is set to 1 when box is unlocked.

// effects
//50 - big fire boom, no damage
//51 - 20 damage
//52 - 30 damage
//53 - 80 damage
//54 - 200 damage
//55 - 1000 damage

//60 - big electric boom, no damage
//61 - 20 damage
//62 - 50 damage
//63 - 100 damage
//64 - 250 damage
//65 - 1000 damage

//70 - big cold boom, no damage
//71 - 20 damage
//72 - 40 damage
//73 - 120 damage
//74 - 300 damage
//75 - 1000 damage

//80 - big poison poof, no damage
//81 - 10 status
//82 - 25 status
//83 - 50 status
//84 - 100 status
//85 - 250 status

//90 - big acid poof, no damage
//91 - 10 status
//92 - 25 status
//93 - 50 status
//94 - 100 status
//95 - 250 status

//100 - charm explosion, level 10
//101 - charm explosion, level 25
//102 - charm explosion, level 50

//105 - daze explosion, level 10
//106 - daze explosion, level 25
//107 - daze explosion, level 50


beginobjectscript;

variables;
	short i_am_open = 0;
	short trap_is_gone = 0;
	short got_warning = 0;
body;

beginstate INIT_STATE;
	set_obj_tool_difficulty(ME,get_memory_cell(0));
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			set_obj_tool_difficulty(ME,0);
		}
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE;

break;

beginstate USE_STATE;
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			trap_is_gone = 1;
		}
		
	if (trap_is_gone == 0) {
		if (get_stat(MECHANICS) >= get_obj_tool_difficulty(ME)) {
			print_str("Open Box: It has a trap, but you are able to disarm it.");
			trap_is_gone = 1;

			if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
				if (get_flag(get_memory_cell(2),get_memory_cell(3)) == 0)
					award_party_xp(BASE_TRAP_XP,trap_lev_to_xp_lev(get_memory_cell(0)));
				set_flag(get_memory_cell(2),get_memory_cell(3),1);
				}
			}
			else if (got_warning == 0) {
				print_str("Open Box: You are able to tell that it has a trap, but your");
				print_str("  Mechanics skill isn't high enough to disarm it. If you open the");
				print_str("  box, you may trigger the trap.");
				got_warning = 1;
				end();
				}
				else { // trigger trap
					print_str("Open Box: You set off a trap!");
					trap_is_gone = 1;
					if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
						set_flag(get_memory_cell(2),get_memory_cell(3),1);
					run_sparkles_on_object(ME,get_memory_cell(1),1,0);
					end();
					}
		}		
		
	if (i_am_open == 0) {
		i_am_open = 1;
		open_container();
		}
		else {
			close_container();
			i_am_open = 0;
			}
break;


beginstate UNLOCK_STATE;
	if (trap_is_gone == 0) {
		print_str("Unlock Spell: A container glows red. It must have a trap.");
		}
break;

